package com.wn.controller;

import com.github.pagehelper.PageInfo;
import com.wn.annotation.RequireRoles;
import com.wn.entity.Emp;
import com.wn.entity.Hotelinfo;
import com.wn.entity.Travelinfo;
import com.wn.service.HotelinfoService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.UUID;

/**
 * (Hotelinfo)表控制层
 *
 * @author makejava
 * @since 2020-10-26 09:30:32
 */
@RestController
@RequestMapping("hotelinfo")
@Api(tags = "酒店信息管理api")
public class HotelinfoController {
    /**
     * 服务对象
     */
    @Resource
    private HotelinfoService hotelinfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getHotelById")
    public Rsp getHotelById(String id) {
        Hotelinfo hotel = hotelinfoService.queryById(id);
        return Rsp.success(hotel);
    }
    /**
     *分页查询数据
     *
     * @return 单条数据
     */
    @SystemControllerLog(description = "分页查询酒店信息")
    @PostMapping("searchSomeHotelByPage")
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    public Rsp searchSomeHotelByPage(@RequestBody PageParam<Hotelinfo> pageParam,
                                     @RequestHeader("token") String token){

            return Rsp.success(hotelinfoService.queryAllByLimit(pageParam));


    }
    /**
     *增加单个数据
     *
     * @param hotel 酒店信息
     * @return 单条数据
     */
    @SystemControllerLog(description = "增加酒店信息")
    @PostMapping("addOneHotel")
    @ApiOperation("增加数据")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    public Rsp addOneHotel(@RequestBody @Valid Hotelinfo hotel, @RequestHeader("token") String token){

            return Rsp.success(hotelinfoService.insert(hotel));

    }

    /**
     *修改单个数据
     *
     * @param hotel 酒店信息
     * @return 单条数据
     */
    @SystemControllerLog(description = "修改酒店信息")
    @PostMapping("updateHotel")
    @ApiOperation("修改单条数据")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    public Rsp updateHotel(@RequestBody @Valid Hotelinfo hotel,@RequestHeader("token") String token){

            return Rsp.success(hotelinfoService.update(hotel));

    }

    /**
     *逻辑删除单个数据
     *
     *
     * @return 单条数据
     */
    @SystemControllerLog(description = "逻辑删除酒店信息")
    @PostMapping("deleteHotelLogical")
    @ApiOperation("逻辑删除单条数据")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    public Rsp deleteHotelLogical(@RequestBody Hotelinfo hotelinfo,@RequestHeader("token") String token){

            return Rsp.success(hotelinfoService.deleteLogical(hotelinfo.getId()));

    }

    @GetMapping("selHotel")
    public List<Hotelinfo> selHotel(Object longitude,Object latitude){
        List<Hotelinfo> hotelinfos = hotelinfoService.selHotel(longitude, latitude);
        return hotelinfos;
    }
}
